package com.github.shiqiyue.learn.guava;

import com.google.common.primitives.Doubles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/***
 * 描述
 * @author wenyao.wu
 * @date 2018/7/3
 */
public class DoublesTest {

    private static final Logger logger = LoggerFactory.getLogger(DoublesTest.class);

    public static void main(String[] args) {
        double[] doubleArray = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};

        //convert array of primitives to array of objects
        List<Double> objectArray = Doubles.asList(doubleArray);
        logger.info("{}", objectArray);

        //convert array of objects to array of primitives
        doubleArray = Doubles.toArray(objectArray);

        logger.info("{}", doubleArray);
        //check if element is present in the list of primitives or not
        logger.info("5.0 is in list? {}", Doubles.contains(doubleArray, 5.0f));

        //return the index of element
        logger.info("5.0 position in list {}", Doubles.indexOf(doubleArray, 5.0f));

        //Returns the minimum
        logger.info("Min: {}", Doubles.min(doubleArray));

        //Returns the maximum
        logger.info("Max: {}", Doubles.max(doubleArray));
    }
}
